////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <assert.h>
#include "CGUICinematicCtrl.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
#include "CGlobals.h"
#include "CUserInterface.h"
#include "CLevelEditor.h"
#include "DoUndoCommands.h"
#include "CListBox.h"
#include "IGUIContextMenu.h"

//#include <algorithm>
#include "CCinematicThread.h"
#include "CFPSGUITable.h"

extern CGlobals* g;
extern CLevelEditor* editor;
extern CUserInterface* ui;

using namespace irr;
using namespace gui;
using namespace core;

typedef struct tgCinematicInfoClipboard
{
	CCinematicThread* m_thread;
	irr::core::array<int> m_columns;
	irr::core::array<void *> m_commandList;
}CINEMATIC_INFO_CLIPBOARD;

void SafeDeleteCinematicInfoClipboard( CINEMATIC_INFO_CLIPBOARD * pClipboard)
{
	delete pClipboard->m_thread;
	pClipboard->m_columns.clear();
	int count = pClipboard->m_commandList.size();
	for(int i=0; i<count; i++)
	{
		array<CCinematicCommand*>* clonedCommands = static_cast< array<CCinematicCommand*>* >(pClipboard->m_commandList[i]);
		int cmdCount = clonedCommands->size();
		for(int j=0; j<cmdCount; j++)
		{
			CCinematicCommand *pCmd = (*clonedCommands)[j];
			delete pCmd;
		}
		delete clonedCommands;
	}
	pClipboard->m_commandList.clear();	
	delete pClipboard;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//
IGUICinematicCtrl *irr::gui::AddGUICinematicCtrl( IGUIEnvironment *env, const core::rect<s32> Rectangle, IGUIElement *parent, s32 id)
{
	if(parent == NULL)
		parent = env->getRootGUIElement();

	CGUICinematicCtrl *tree = new CGUICinematicCtrl(env, parent, id, Rectangle);
	

	return tree;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
CGUICinematicCtrl::~CGUICinematicCtrl()
{
	m_CopyCinematic = NULL;

	if (table)
		table->drop();

	if(Font)
		Font->drop();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
CGUICinematicCtrl::CGUICinematicCtrl(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle):
IGUICinematicCtrl(environment, parent, id, rectangle),
Font(NULL),
OverrideFont(NULL),
video(environment->getVideoDriver())
{

	int scrollBarSize = Environment->getSkin()->getSize(EGDS_SCROLLBAR_SIZE);
	rect<s32> r = this->getRelativePosition();

	table = new CFPSGUITable(Environment , this , -1 ,  rect<s32>( 0 , 0 , r.getWidth() , r.getHeight()) , false , false , false  );
	
	table->addColumn(L"Name" , 0 );
	table->setColumnWidth( 0 , 100);
	table->setSelectableColumn(true);

	const int k_max_columns = MAX_COLUMNS;

	for (int i = 1 ; i < k_max_columns+2 ; i ++  )
	{
		stringw name = L"";
		name += ((i - 1) * EVENTS_INTERVAL);
		table->addColumn( name.c_str() , i );
		table->setColumnWidth( i , 20);
	}

	m_CopyCinematic = NULL;
	rightClickedRow = -1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::draw()
{
	if(!IsVisible)
		return;
	
	IGUISkin* skin = Environment->getSkin();
	irr::video::IVideoDriver* driver = Environment->getVideoDriver();

	core::rect<s32>* clipRect = 0;
	clipRect = &AbsoluteClippingRect;

	// draw background
	core::rect<s32> frameRect(AbsoluteRect);

	skin->draw3DSunkenPane(this, skin->getColor(EGDC_3D_HIGH_LIGHT), true,
		true, frameRect, clipRect);
	
	// draw items

	core::rect<s32> clientClip(AbsoluteRect);
	clientClip.UpperLeftCorner.Y += 1;
	clientClip.UpperLeftCorner.X += 1;
	clientClip.LowerRightCorner.X -= skin->getSize(EGDS_SCROLLBAR_SIZE)+1;
	clientClip.LowerRightCorner.Y -= skin->getSize(EGDS_SCROLLBAR_SIZE)+1;

	if (clipRect)
		clientClip.clipAgainst(*clipRect);		

	IGUIElement::draw();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
bool CGUICinematicCtrl::OnEvent(const SEvent& event)
{
	switch(event.EventType)
	{
	case irr::EET_KEY_INPUT_EVENT:
		{
			break;		
		}
		break;
	case EET_GUI_EVENT:
		{
			switch(event.GUIEvent.EventType)
			{
			case gui::EGET_SCROLL_BAR_CHANGED:
				{
					return true;
					//break;
				}
				break;
			case gui::EGET_ELEMENT_FOCUS_LOST:
				{					
					break;
				}
				break;
			case gui::EGET_ELEMENT_HOVERED:
				{
					break;
				}
				break;
			case EGET_MENU_ITEM_SELECTED:
				{
					IGUIContextMenu* menu = (IGUIContextMenu*)event.GUIEvent.Caller;
						s32 id = menu->getItemCommandId(menu->getSelectedItem());

					switch(id)
					{
					case CINEMATIC_CONTEXT_NEW_BASIC_THREAD:
						{
							CCinematicThread* cmt = new CCinematicThread(E_THREAD_TYPE_BASIC);
							AddThread(cmt);	
							return true;						
						}
						break;
					
					case CINEMATIC_CONTEXT_NEW_OBJ_THREAD:
						{
							CCinematicThread* cmt = new CCinematicThread(E_THREAD_TYPE_OBJ);
							AddThread(cmt);						
							return true;						
						}
						break;

					case CINEMATIC_CONTEXT_NEW_CAMERA_THREAD:
						{
							CCinematicThread* cmt = new CCinematicThread(E_THREAD_TYPE_CAMERA);
							AddThread(cmt);						
							return true;						
						}
						break;

					case CINEMATIC_CONTEXT_NEW_PLAYER_THREAD:
						{
							CCinematicThread* cmt = new CCinematicThread(E_THREAD_TYPE_PLAYER);
							//auto-link spider man to player thread
							ui->m_CinematicEditor.AutoSetPlayerThreadObj(cmt);
							AddThread(cmt);						
							return true;						
						}
						break;
					case CINEMATIC_CONTEXT_RENAME_THREAD:
						{
							if( wcscmp(GetSelectedText(), L"Basic Thread") != 0
								&& wcscmp(GetSelectedText(), L"Player Thread") != 0
								&& wcscmp(GetSelectedText(), L"Camera Thread") != 0
								)
							{
								// let renameWindow's parent be the root window,because it must be not hided by others.
								IGUIWindow* renameWindow = g->guienv->addMessageBox(L"Rename the Thread", 0, true, EMBF_OK | EMBF_CANCEL, this->getParent()->getParent(), WND_ID_RENAME_THREAD);
								IGUIEditBox* editBox = g->guienv->addEditBox(GetSelectedText(), rect<s32>(20,20,300,40), true, (IGUIElement *)renameWindow, WND_ID_EDIT_RENAME_THREAD);
							}
							else
							{
								g->guienv->addMessageBox(L"Error!", L"Only Object Thread can be Renamed!");
							}

							return true;
						}
						break;
					case CINEMATIC_CONTEXT_DELETE_THREAD:
						{
							if (rightClickedRow != -1)
							{								
								RemoveThread(rightClickedRow);
								return true;						
							}
						}
						break;
					case CINEMATIC_CONTEXT_CLONE_THREAD:
						{
							void* cdata = GetTableData( GetSelectedRow() , 0 );
							CCinematicThread* cmt = static_cast<CCinematicThread*>(cdata);	
							if (cmt)
							{
								CCinematicThread* newCmt = new CCinematicThread(E_THREAD_TYPE_OBJ);							
								//copy attributes from the right clicked row ?							
								newCmt->m_Name = cmt->m_Name;
								newCmt->m_Type = cmt->m_Type;
								newCmt->m_Obj = cmt->m_Obj;
								
								int newRow = AddThread(newCmt);		

								int columns = GetTableColumns();
								
								for (u32 j = 1 ; j < columns ; j++ )
								{
									void * data = GetTableData( GetSelectedRow() , j );
									array<CCinematicCommand*>* commands = static_cast<array<CCinematicCommand*>*>(data);
									if (commands && (*commands).size() > 0)
									{
										array<CCinematicCommand*>* clonedCommands = new array<CCinematicCommand*>;
										//clone commands here 
										//xml->writeElement(L"time", false, L"stamp", stringw( (j - 1) * 50).c_str() );
										//xml->writeLineBreak();
										SetTableData(newRow , j , (void*) clonedCommands );
										for (u32 k = 0 ; k < (*commands).size(); k++)
										{
											CCinematicCommand* cmd = (*commands)[k];
											CCinematicCommand* newCmd = new CCinematicCommand ( *cmd );
										//	xml->writeElement(L"command", false, L"name", cmd->m_Name.c_str() , L"id" , stringw(cmd->m_id).c_str());
										//	xml->writeLineBreak();
										//	cmd->m_Attributes->write(xml, false);
										//	xml->writeClosingTag(L"command");
										//	xml->writeLineBreak();
											clonedCommands->push_back( newCmd );
										}	

										//xml->writeClosingTag(L"time");
										//xml->writeLineBreak();
										//delete commands;
									}
								}
							}
							else
							{
								//something failed 
							}
						}	
						break;
					case CINEMATIC_CONTEXT_COPY_THREAD:
						{
							void* cdata = GetTableData( GetSelectedRow() , 0 );
							CCinematicThread* cmt = static_cast<CCinematicThread*>(cdata);	
							if (cmt)
							{
								CINEMATIC_INFO_CLIPBOARD *pClipboard = new CINEMATIC_INFO_CLIPBOARD;
								CCinematicThread* newCmt = new CCinematicThread(E_THREAD_TYPE_OBJ);
								pClipboard->m_thread = newCmt;
								//copy attributes from the right clicked row ?							
								newCmt->m_Name = cmt->m_Name;
								newCmt->m_Type = cmt->m_Type;
								newCmt->m_Obj = cmt->m_Obj;
								
								int columns = GetTableColumns();
								
								for (u32 j = 1 ; j < columns ; j++ )
								{
									void * data = GetTableData( GetSelectedRow() , j );
									array<CCinematicCommand*>* commands = static_cast<array<CCinematicCommand*>*>(data);
									if (commands && (*commands).size() > 0)
									{										
										array<CCinematicCommand*>* clonedCommands = new array<CCinematicCommand*>;
										pClipboard->m_columns.push_back( j );
										pClipboard->m_commandList.push_back( (void*) clonedCommands );
										for (u32 k = 0 ; k < (*commands).size(); k++)
										{
											CCinematicCommand* cmd = (*commands)[k];
											CCinematicCommand* newCmd = new CCinematicCommand ( *cmd );
											clonedCommands->push_back( newCmd );
										}										
									}
								}
								if( ui->m_Clipboard )
								{
									SafeDeleteCinematicInfoClipboard( static_cast<CINEMATIC_INFO_CLIPBOARD*>(ui->m_Clipboard) );
									ui->m_Clipboard = NULL;
								}
								ui->m_Clipboard = pClipboard;
							}							
						}
						break;
					case CINEMATIC_CONTEXT_PASTE_THREAD:
						{
							if( ui->m_Clipboard == NULL )
							{
								break;
							}

							CINEMATIC_INFO_CLIPBOARD *pClipboard = reinterpret_cast<CINEMATIC_INFO_CLIPBOARD *>(ui->m_Clipboard);
							if( pClipboard->m_thread == NULL )
							{
								break;
							}

							int newRow = AddThread(pClipboard->m_thread);		

							int count = pClipboard->m_columns.size();
							
							for (u32 i = 0 ; i < count ; i++ )
							{
								SetTableData(newRow , pClipboard->m_columns[i] , (void*) pClipboard->m_commandList[i] );
								SetTableColor(newRow , pClipboard->m_columns[i],  SColor(255,0,0,0) , L"X") ;
							}
							ui->m_Clipboard = NULL;
							
						}
						break;
					case CINEMATIC_CONTEXT_COPY_GROUP_CINEMATIC:
						{
							irr::core::array<u32> activeColumns = table->getAllActiveColumns();
							if (rightClickedRow != -1 && activeColumns.size()>1)
							{
								CINEMATIC_INFO_CLIPBOARD *pClipboard = new CINEMATIC_INFO_CLIPBOARD;
								pClipboard->m_thread = NULL;
								
								for (u32 i = 0; i < activeColumns.size() ; i++ )
								{
									int col = activeColumns[i];
									void * data = GetTableData( GetSelectedRow() , col );
									array<CCinematicCommand*>* commands = static_cast<array<CCinematicCommand*>*>(data);
									if (commands && (*commands).size() > 0)
									{										
										array<CCinematicCommand*>* clonedCommands = new array<CCinematicCommand*>;
										pClipboard->m_columns.push_back( activeColumns[i] );
										pClipboard->m_commandList.push_back( (void*) clonedCommands );
										for (u32 k = 0 ; k < (*commands).size(); k++)
										{
											CCinematicCommand* cmd = (*commands)[k];
											CCinematicCommand* newCmd = new CCinematicCommand ( *cmd );
											clonedCommands->push_back( newCmd );
										}										
									}
								}
								if( ui->m_Clipboard )
								{
									SafeDeleteCinematicInfoClipboard( static_cast<CINEMATIC_INFO_CLIPBOARD*>(ui->m_Clipboard) );
									ui->m_Clipboard = NULL;
								}
								ui->m_Clipboard = pClipboard;
								table->clearAllActiveColumns();
							}
						}
						break;
					case CINEMATIC_CONTEXT_PASTE_GROUP_CINEMATIC:
						{
							if( ui->m_Clipboard == NULL )
							{
								break;
							}

							CINEMATIC_INFO_CLIPBOARD *pClipboard = reinterpret_cast<CINEMATIC_INFO_CLIPBOARD *>(ui->m_Clipboard);
							if( pClipboard->m_thread != NULL )
							{
								break;
							}
							
							for(int i=0; i< pClipboard->m_columns.size(); i++)
							{
								int copyColumn = pClipboard->m_columns[i];
								int targetColumn = copyColumn;
								//paste group commands here 
								void* cdata = GetTableData(rightClickedRow  , copyColumn );

								if (targetColumn != 0)
								{
									// 
									array<CCinematicCommand*> * cmds = static_cast< array<CCinematicCommand*> *>(cdata);
									//commmands already in place 	
									if (cmds != 0)
									{

									}	
									else  //create commands here 
									{
										cmds = new array<CCinematicCommand*>;	
										SetTableData(rightClickedRow , targetColumn, (void*) cmds );
									}

									//get commands from 
									array<CCinematicCommand*> * pCurrentCommandList = static_cast<array<CCinematicCommand*> *>(pClipboard->m_commandList[i]);
									for(int j=0;j<pCurrentCommandList->size();j++)
									{										
										CCinematicCommand* newCmd = new CCinematicCommand( *((*pCurrentCommandList)[j]) );
										cmds->push_back(  newCmd );
									}
									SetTableColor(rightClickedRow , targetColumn,  SColor(255,0,0,0) , L"X") ;									
								}
							}
							ui->m_Clipboard = NULL;
						}
						break;
					case CINEMATIC_CONTEXT_COPY_CINEMATIC:
					case CINEMATIC_CONTEXT_CUT_CINEMATIC:
						{
							if (rightClickedRow != -1 && rightClickedColumn)
							{
								void* cdata = GetTableData( rightClickedRow , rightClickedColumn );
							
								if (GetSelectedColumn() != 0)
								{
									  // 
									  array<CCinematicCommand*> * cmds = static_cast< array<CCinematicCommand*> *>(cdata);

									  if (cmds != 0)
									  {
											m_CopyCinematic = cmds;

											if (id == CINEMATIC_CONTEXT_CUT_CINEMATIC)
											{
												//SetTableData(  rightClickedRow , rightClickedColumn  , (new array<CCinematicCommand*>) );
												//modify by lichuan, 2009/12/18
												SetTableData(  rightClickedRow , rightClickedColumn  , NULL );
												SetTableColor( rightClickedRow , rightClickedColumn , SColor(255,0,0,0) , L"") ;
											}
											//enable paste command 
											menu->setItemEnabled(2 , true );
											
									  }
									  else //noting here .. this should not happen
									  {
										   printf("noting here .. this should not happen\n");
										   assert(0);
									  }
								}
							}
							break;
						}
						break;
					case CINEMATIC_CONTEXT_PASTE_CINEMATIC:
						{
							if (m_CopyCinematic != 0 && rightClickedRow != -1 && rightClickedColumn != -1)
							{
								//paste commands here 
								void* cdata = GetTableData(rightClickedRow  , rightClickedColumn );

								if (rightClickedColumn != 0)
								{
									// 
									array<CCinematicCommand*> * cmds = static_cast< array<CCinematicCommand*> *>(cdata);
									//commmands already in place 	
									if (cmds != 0)
									{

									}	
									else  //create commands here 
									{
										cmds = new array<CCinematicCommand*>;	
										SetTableData(rightClickedRow , rightClickedColumn, (void*) cmds );
									}

									//get commands from 
									for (int i = 0 ; i < m_CopyCinematic->size() ; i ++)
									{
										CCinematicCommand* newCmd = new CCinematicCommand(*(*m_CopyCinematic)[i]);
										cmds->push_back(  newCmd );

									}

									SetTableColor(rightClickedRow , rightClickedColumn,  SColor(255,0,0,0) , L"X") ;
									m_CopyCinematic = NULL;
									 
								}
								//refresh cinematic editor 
							}
							break;
						}
						break;
					}
				}
				break;
			}
			break;	
		}
		break;
	case EET_MOUSE_INPUT_EVENT:
		{
			core::position2d<s32> p(event.MouseInput.X, event.MouseInput.Y);
			
			switch(event.MouseInput.Event)
			{
			case EMIE_MOUSE_WHEEL:
				{
					return true;
				}
				break;
			case EMIE_RMOUSE_PRESSED_DOWN:
				{	
					rect<s32> rel = this->getAbsolutePosition();
					int menuX = p.X - rel.UpperLeftCorner.X;
					int menuY = p.Y - rel.UpperLeftCorner.Y;
					
					bool Enabled = false;	
					//if  is a thread where i clicked 
					// enabled = true
					s32 row = -1 , column = -1; 
					table->getRowColumn(p.X , p.Y , row , column);

					if (row >= 0)
						Enabled = true;

					
					rightClickedRow = row;
					rightClickedColumn = column;

				
					if (column == 0)
					{					
						IGUIContextMenu* menu = g->guienv->addContextMenu(rect<s32>(menuX, menuY, menuX + 200, menuY + 200) , this , CINEMATIC_CONTEXT_MENU);										

						menu->addItem(L"New Object Thread", CINEMATIC_CONTEXT_NEW_OBJ_THREAD);			
						menu->addItem(L"New Basic Thread", CINEMATIC_CONTEXT_NEW_BASIC_THREAD);
						menu->addItem(L"New Camera Thread", CINEMATIC_CONTEXT_NEW_CAMERA_THREAD);
						menu->addItem(L"New Player Thread", CINEMATIC_CONTEXT_NEW_PLAYER_THREAD );
						menu->addSeparator();
						menu->addItem(L"Rename Thread", CINEMATIC_CONTEXT_RENAME_THREAD, Enabled);
						menu->addItem(L"Remove Thread", CINEMATIC_CONTEXT_DELETE_THREAD , Enabled);
						menu->addItem(L"Clone Thread", CINEMATIC_CONTEXT_CLONE_THREAD , Enabled);
						menu->addItem(L"Copy Thread", CINEMATIC_CONTEXT_COPY_THREAD , Enabled);
						menu->addItem(L"Paste Thread", CINEMATIC_CONTEXT_PASTE_THREAD ,ui->m_Clipboard!=NULL? true:false );
						bringToFront( menu );	
					}
					else if ( row >= 0)
					{
						//get data from here ....
						void* data = table->getCellData(row , column);
						
						array<CCinematicCommand*> * cmds = static_cast< array<CCinematicCommand*> *>(data);

						IGUIContextMenu* menu = g->guienv->addContextMenu(rect<s32>(menuX, menuY, menuX + 200, menuY + 200) , this , CINEMATIC_CONTEXT_MENU);
						if (cmds) 
						{																	
							//cast to ccinematic command 
							//show window to edit  							
							menu->addItem(L"Copy", CINEMATIC_CONTEXT_COPY_CINEMATIC , (cmds && cmds->size()) ? true : false );			
							menu->addItem(L"Cut", CINEMATIC_CONTEXT_CUT_CINEMATIC , (cmds && cmds->size()) ? true : false );
							menu->addItem(L"Paste", CINEMATIC_CONTEXT_PASTE_CINEMATIC , m_CopyCinematic != 0 ? true : false );		
						}

						irr::core::array<u32> ativeColumns = table->getAllActiveColumns();
						if( ativeColumns.size() > 1 )
						{
							menu->addSeparator();
							menu->addItem(L"Copy Group", CINEMATIC_CONTEXT_COPY_GROUP_CINEMATIC , (ativeColumns.size()>1) ? true : false );							
						}
						if( ui->m_Clipboard )
						{
							menu->addItem(L"Paste Group", CINEMATIC_CONTEXT_PASTE_GROUP_CINEMATIC , (ui->m_Clipboard!=NULL) ? true : false );
						}
					}
					break;					
				}
				break;
			case EMIE_RMOUSE_LEFT_UP:
				{	
					break;
				}
				break;
			default:
				break;
			}
		}
		break;
	default:
		break;
	}

	return Parent ? Parent->OnEvent(event) : false;
	//return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
bool CGUICinematicCtrl::SetOverrideFont(IGUIFont *font)
{
	if(font == OverrideFont)
		return false;
	
	if(OverrideFont)
		OverrideFont->drop();
	
	OverrideFont = font;
	
	if(OverrideFont)
		OverrideFont->grab();	

	//recalculateItemHeight();
	return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
IGUIFont *CGUICinematicCtrl::GetOverrideFont()
{
	return OverrideFont;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
int CGUICinematicCtrl::AddThread(CCinematicThread* t)
{	
	int index = GetTableRows();
	table->addRow(index);
	table->setCellText( index , 0 , t->m_Name.c_str() );
	table->setCellData( index , 0 , (void*)t);

	return index;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::RemoveThread(s32 index)
{	
	//delete Cinematic thread data 
	//delete all cinematic arrays if any 
	table->removeRow(index);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
const wchar_t* CGUICinematicCtrl::GetSelectedText()
{
	return table->getCellText(	table->getSelected() , table->getSelectedColumn() );
}

void CGUICinematicCtrl::SetSelectedText(const wchar_t* text)
{
	return table->setCellText(	table->getSelected() , table->getSelectedColumn(), text );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void* CGUICinematicCtrl::GetSelectedData()
{
	return table->getCellData(	table->getSelected() , table->getSelectedColumn() );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::SetSelectedData(void * data)
{
	table->setCellData(	table->getSelected() , table->getSelectedColumn() , data);
		
	//table->setCellColor( table->getSelected() , table->getSelectedColumn() , SColor( 255 , 255 , 0 ,255 ));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::SetSelectedColor(SColor color , stringw text , s32 columns)
{	
	s32 start =  table->getSelectedColumn()  ;
	s32 end =  table->getSelectedColumn() + columns;
	
	for ( int i = start ; i < end ; i ++ )
	{
		table->setCellText(	table->getSelected() , i , text.c_str() );			
		table->setCellColor( table->getSelected() , i , color);			
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
s32 CGUICinematicCtrl::GetTableRows()
{
	return table->getRowCount();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
s32 CGUICinematicCtrl::GetTableColumns()
{
	return table->getColumnCount();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
const wchar_t* CGUICinematicCtrl::GetTableText(s32 r, s32 c)
{
	return table->getCellText( r, c );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void* CGUICinematicCtrl::GetTableData(s32 r, s32 c)
{
	return table->getCellData( r, c );
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::SetTableData(s32 r, s32 c, void* v)
{
	 table->setCellData( r, c , v);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
s32 CGUICinematicCtrl::GetSelectedRow()
{
	return table->getSelected();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
s32 CGUICinematicCtrl::GetSelectedColumn()
{
	return table->getSelectedColumn();
}

void CGUICinematicCtrl::SetSelectedColumn(s32 column)
{
	return table->setSelectedColumn(column);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//
void CGUICinematicCtrl::SetTableColor(s32 r , s32 c , SColor color , stringw text , s32 columns)
{
	s32 start =  c  ;
	s32 end =  c + columns;
	
	for ( int i = start ; i < end ; i ++ )
	{
		table->setCellText( r , i , text.c_str());			
		table->setCellColor( r  , i , color);		
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////